require 'xm/platform'
engine = XM::Platform.config.pdm_engine
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
pwd = XM::Platform.root.join("comps/pdm_engine")
#java_home = XM::Platform.root.join("jre1.8.0")
error_log = XM::Platform.root.join("comps/pdm_engine/probeservers/log/error_#{timestamp}.log")
group(:component) do  
  group(:pdm_engine, :order => 20, :description => "The pdm engine") do
    java(:se_engine, "comps/pdm_engine",
         :order => 50,
         :stdout =>"NUL",
         :classpath => %W[conf],
         :java_options => %W{-server -noverify -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=engine_#{timestamp}.hprof -XX:ThreadStackSize=256 -XX:MaxMetaspaceSize=#{pdm_engine_Perm} -Xms#{pdm_engine_sampling_mem} -Xmx#{pdm_engine_sampling_mem} -XX:-UseGCOverheadLimit -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -verbose:gc -Xloggc:#{pwd}/log/gc_Engine.log -Dfile.encoding=UTF-8 -Djava.library.path=bin -Dapplication.name=SE-ENGINE -Dapp.class.path=#{pwd}/lib/thirdpart;#{pwd}/lib/shared;#{pwd}/lib/se-shared;#{pwd}/lib/se-engine -Djava.system.class.loader=com.codesafe.SafeClassLoader},
         :start => {:main => "cn.com.betasoft.dsat.se.Engine"},
         :stop => :kill)
    java(:probe_servers, "comps/pdm_engine/probe_servers",
           :order => 50,
           :stdout =>"NUL",
           :mandatory => true,
           :start => {
               :jar => "start.jar"
           },
           :started => {:port => "30904", :max => 5.minutes},
           :stopped => {:max => 1.minutes},
           :java_options => %W{-XX:MaxMetaspaceSize=#{probe_servers_perm} -server -noverify -Xms#{probe_servers_mem_Xms} -Xmx#{probe_servers_mem_Xmx} -Dkairos_read_timeout=30000 -Dorg.eclipse.jetty.util.log.class=ch.qos.logback.classic.Logger -XX:-LoopUnswitching -XX:+ScavengeBeforeFullGC -XX:+UseTLAB -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:ErrorFile=#{error_log} -XX:+PrintGCTimeStamps -DSTOP.PORT=8040 -DSTOP.KEY=secret},
           :stop => :kill)
    if Dir.glob(engine.root.join("lib/probes/network_device*.jar")).size > 0
      launch(:probe_host, "comps/pdm_engine/legacy",
         :order => 50,
         :stdout =>"NUL",
         :start => "probeHost_vc100.exe",
	     :started => {:port => 30920},
         :stop => :kill)
    end

    if Dir.glob(engine.root.join("lib/probes/network_device*.jar")).size > 0
      launch(:probe_host2, "comps/pdm_engine/legacy2",
         :order => 50,
         :stdout =>"NUL",
         :start => "probeHost_vc100.exe",
	     :started => {:port => 30921},
         :stop => :kill)
    end
	 
  
  end

end